using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using Kis.Xroad.Eu;
using NUnit.Framework;
using Xtee.Core.Types;

namespace Xtee.CodeDom.Test.SimpleTypes.Usage
{
    [TestFixture]
    public class UsageTest
    {
        [Test]
        public void SimpleType()
        {
           
            Simple simple  = new Simple(5);
            Assert.AreEqual(5,(int)simple);
           
            simple = 6;
            Assert.AreEqual(6,simple.Value);

            simple = new Simple("6");
            Assert.AreEqual(6, simple);
        }
        [ExpectedException(typeof(XteeSimpleTypePatternMismatchException))]
        [Test]
        public void SimpleWrongPatternType()
        {
            Simple simple = 7; 
        }
        [Test]
        public void SimpleDerivedType()
        {
            DerivedSimple simple = new DerivedSimple(5);
            Assert.AreEqual(5, (int)simple);
         
            simple = 5; 
            Assert.AreEqual(5, simple.Value);
            simple = new DerivedSimple("5");
            Assert.AreEqual(5, simple);
        }

        [Test]
        public void SimpleDateTimeType()
        {
            SimpleDateTime simple = new SimpleDateTime(DateTime.Parse("2011-01-01"));
            Assert.AreEqual("2011-01-01T00:00:00.0000000", simple.ToString());

            simple = new SimpleDateTime("2011-01-01T00:00:00.0000000");
            Assert.AreEqual(DateTime.Parse("2011-01-01"), (DateTime)simple);
        
        }

        [Test]
        public void SimpleFractionType()
        {
            SimpleFractionDigits simple =  5.55m;
            simple = new SimpleFractionDigits("5.55");
            Assert.AreEqual((decimal)5.55, (decimal)simple);
        }
        
     
        [Test]
        public void SimpleInvalidFractionDigitsTryParseFalse()
        {
            SimpleFractionDigits digits;
            Assert.IsFalse(SimpleFractionDigits.TryParse("5.556", out digits));
        }
        [Test]
        public void SimpleInvalidFractionDigitsTryParseTrue()
        {
            SimpleFractionDigits digits;
            Assert.IsTrue(SimpleFractionDigits.TryParse("5.56", out digits));
            Assert.AreEqual((decimal)5.56, (decimal)digits);
             
        }
         
    }
}
